//
//  ZClient.h
//  LuckyTools
//
//  Created by ZhàoYǒng on 16/3/1.
//  Copyright © 2016年 ZhàoYǒng. All rights reserved.
//

#import <AFNetworking/AFNetworking.h>
#import <ReactiveObjC/ReactiveObjC.h>
#import "ZParsedResponse.h"

@protocol ZClientDelegate<NSObject>

@optional

- (NSDictionary *)clientReformParameters:(NSDictionary *)parameters;
- (NSDictionary *)headerFields;
- (ZParsedResponse *)parseResponse:(id)responseObject;

@end

// Error domain
extern NSString *const ZClientErrorDomain;
// JSON parsing error code
extern const NSInteger ZClientErrorJSONParsingFailed;
/* error code
 *
 */

@interface ZClient : AFHTTPSessionManager

@property (nonatomic, weak) id<ZClientDelegate> clientDelegate;

- (RACSignal *)enqueueRequest:(NSURLRequest *)request resultClass:(Class)resultClass;

@end

@interface ZClient(NSURLSessionDataTask)

/*
 * Create forms Requests
 * method			- `GET` `POST`
 * path				- The path
 * parameters - The parameters
 * Return NSMutableURLRequest instance
 */
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)path parameters:(id)parameters;

/*
 * Create mutable binary flow request
 * method			- set POST
 * path				- The request path
 * parameters - request parameters
 * Returns NSMutableURLRequest instance for submit image/file
 */
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters constructingBodyWithBlock:(void(^)(id <AFMultipartFormData> formData))block;

@end
